package com.mdp.workflow.bus.candidate.strategy;

import com.mdp.core.err.BizException;
import com.mdp.core.utils.ObjectTools;
import com.mdp.core.utils.StrUtils;
import com.mdp.workflow.api.FlowProcinstService;
import com.mdp.workflow.biz.ru.entity.ProcinstExpand;
import com.mdp.workflow.biz.ru.service.ProcinstExpandService;
import com.mdp.workflow.bus.candidate.TaskCandidateStrategy;
import com.mdp.workflow.comm.dict.CandidateStrategy;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Set;

/**
 * 9哥
 *
 *@author 唛盟开源9哥
 */
@Component
public class MonitorsStrategy implements TaskCandidateStrategy { 

    @Lazy
    @Autowired
    ProcinstExpandService expandService;

    @Override
    public CandidateStrategy getStrategy() {
        return CandidateStrategy.MONITORS;
    }

    @Override
    public void validateParam(String param) {

    }

    @Override
    public Set<String> calculateUsers(DelegateExecution execution, String param) {
        ProcinstExpand expand=expandService.getProcinstExpandFirstCache(execution.getProcessInstanceId());
        if(ObjectTools.isEmpty(expand.getMonitors())){
            throw new BizException("expand-monitors-not-set","流程未设置监控人");
        }
        return StrUtils.splitToStringSet(expand.getSponsors());
    }


    @Override
    public boolean isParamRequired() {
        return false;
    }



}
